﻿Imports System.Data
Partial Class Account_MembersOnly
    Inherits System.Web.UI.Page

    Dim conString As New Data.OleDb.OleDbConnection
    Dim dataSet As New Data.DataSet
    Dim dataAdapter As New Data.OleDb.OleDbDataAdapter

    Dim dbProvider As String
    Dim dbSource As String
    Dim dbSource2 As String
    Dim sqlCommand As String
    Dim MaxRows As Integer
    Dim newestOrganization As String
    Dim rows As Integer



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"

        dbSource = "Data Source = "
        dbSource2 = Server.MapPath("~/Database/ImagineCup.mdb")

        'connection string to the global db, ImagineCup.
        conString.ConnectionString = dbProvider & dbSource & dbSource2

        conString.Open()

        sqlCommand = "SELECT * FROM ImagineCup_Org"
        dataAdapter = New Data.OleDb.OleDbDataAdapter(sqlCommand, conString)
        dataAdapter.Fill(dataSet, "OrganizationTbl")

        conString.Close()

        MaxRows = dataSet.Tables("OrganizationTbl").Rows.Count
        rows = MaxRows - 1

        newestOrganization = dataSet.Tables("OrganizationTbl").Rows(rows).Item("org_Name")

        lblRows.Text = "Organizations currently in the database: " & MaxRows
        lblNewestOrganization.Text = "Newest Organization: " & newestOrganization

        conString.Close()

        checkifexistingOrg()
    End Sub

    Public Sub checkifexistingOrg()

        Dim UserLogged As String
        Dim matched As Integer

        UserLogged = Membership.GetUser().UserName

        conString.Open()

        sqlCommand = "SELECT * FROM ImagineCup_Org WHERE UserName= '" & UserLogged & "'"
        dataAdapter = New OleDb.OleDbDataAdapter(sqlCommand, conString)
        dataAdapter.Fill(dataSet, "OrganizationTbl")

        conString.Close()

        MaxRows = dataSet.Tables("OrganizationTbl").Rows.Count
        matched = MaxRows - 1


        If matched < 0 Then

            lblcheck.Visible = False
            hyperCreate.Visible = False

        Else

            lblcheck.Visible = True
            hyperCreate.Visible = True

        End If
    End Sub

End Class
